<script setup lang="ts">
import {
  DisplaySettingsFilled as HomeIcon,
  SettingsRound as SysmanagerIcon,
  SupervisorAccountFilled as UserManagerIcon,
  ManageAccountsFilled as RoleManagerIcon,
  SecurityFilled as AuthManagerIcon,
  ShoppingBagFilled as GoodsIcon,
  ShoppingCartCheckoutFilled as OrderIcon,
  ListRound as ListIcon,
  PostAddFilled as GoodsAddIcon
} from '@vicons/material'
import {} from '@vicons/ionicons5'
import { h } from 'vue'
import type { Component } from 'vue'
import { NIcon } from 'naive-ui'
import { RouterLink, useRoute } from 'vue-router'

const route = useRoute()

const renderIcon = (icon: Component) => {
  return () => h(NIcon, null, { default: () => h(icon) })
}

defineOptions({
  name: 'BaseMenu'
})

const menuOptions = [
  {
    label: () =>
      h(
        RouterLink,
        {
          to: {
            name: 'console'
          }
        },
        { default: () => '控制台' }
      ),
    key: 'console',
    icon: renderIcon(HomeIcon)
  },
  {
    label: '商品管理',
    key: 'goods',
    children: [
      {
        label: () =>
          h(
            RouterLink,
            {
              to: {
                name: 'goods-list'
              }
            },
            { default: () => '商品列表' }
          ),
        key: 'goods-list',
        icon: renderIcon(ListIcon)
      },
      {
        label: () =>
          h(
            RouterLink,
            {
              to: {
                name: 'goods-add'
              }
            },
            { default: () => '商品添加' }
          ),
        key: 'goods-add',
        icon: renderIcon(GoodsAddIcon)
      }
    ],
    icon: renderIcon(GoodsIcon)
  },
  {
    label: '订单管理',
    key: 'order',
    children: [
      {
        label: () =>
          h(
            RouterLink,
            {
              to: {
                name: 'order-list'
              }
            },
            { default: () => '订单列表' }
          ),
        key: 'order-list',
        icon: renderIcon(ListIcon)
      }
    ],
    icon: renderIcon(OrderIcon)
  },
  {
    label: '系统管理',
    key: 'system',
    children: [
      {
        label: () =>
          h(
            RouterLink,
            {
              to: {
                name: 'system-user'
              }
            },
            { default: () => '用户管理' }
          ),
        key: 'system-user',
        icon: renderIcon(UserManagerIcon)
      },
      {
        label: () =>
          h(
            RouterLink,
            {
              to: {
                name: 'system-role'
              }
            },
            { default: () => '角色管理' }
          ),
        key: 'system-role',
        icon: renderIcon(RoleManagerIcon)
      },
      {
        label: () =>
          h(
            RouterLink,
            {
              to: {
                name: 'system-auth'
              }
            },
            { default: () => '权限管理' }
          ),
        key: 'system-auth',
        icon: renderIcon(AuthManagerIcon)
      }
    ],
    icon: renderIcon(SysmanagerIcon)
  }
]
</script>

<template>
  <n-scrollbar style="height: calc(100vh - 56px)">
    <n-menu :options="menuOptions" :value="route.name" :indent="18" :collapsed-width="64" />
  </n-scrollbar>
</template>

<style scoped></style>
